package org.luxor.cloud.portal.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.*;
import org.luxor.cloud.portal.entity.OauthClientDetailsEntity;
import org.luxor.cloud.portal.entity.OauthClientResourceRefEntity;
import org.luxor.cloud.portal.service.IOauthClientResourceRefService;
import org.luxor.commons.core.validator.group.AddGroup;
import org.luxor.commons.core.validator.group.UpdateGroup;
import org.luxor.commons.core.web.controller.BaseRestController;
import org.luxor.commons.core.web.data.R;
import org.luxor.commons.jdbc.metadata.PageQuery;
import org.luxor.commons.jdbc.metadata.PageResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

/**
 * 客户端与可访问资源的关联关系
 *
 * @author administrator @date 2020-10-29 14:27:54
 */
@RestController
@RequestMapping("portal/oauthClientResourceRef")
@Api(tags = "客户端与可访问资源的关联关系")
public class OauthClientResourceRefController extends BaseRestController {

    @Resource
    private IOauthClientResourceRefService oauthClientResourceRefService;

    @ApiOperation("分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页数", paramType = "query", required = true, defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页记录数", paramType = "query", required = true, defaultValue = "10"),
            @ApiImplicitParam(name = "orders", value = "排序条件，如：[{\"column\":\"id\",\"asc\":true}]", paramType = "query")
    })
    @GetMapping("/list")
    public R<IPage<OauthClientResourceRefEntity>> list(@ApiIgnore Page page, @ApiParam(value = "查询条件") Map query) {
        IPage<OauthClientResourceRefEntity> data = oauthClientResourceRefService.page(page, query);
        return R.ok(data);
    }

    @ApiOperation("详情信息")
    @ApiImplicitParam(name = "id", value = "主键ID", paramType = "path", required = true)
    @GetMapping("/info/{id}")
    public R<OauthClientResourceRefEntity> info(@PathVariable("id") Long id) {
        OauthClientResourceRefEntity oauthClientResourceRef = oauthClientResourceRefService.getById(id);
        return R.ok(oauthClientResourceRef);
    }

    @ApiOperation("保存")
    @PostMapping("/save")
    public R<OauthClientResourceRefEntity> save(@Validated(AddGroup.class) @RequestBody OauthClientResourceRefEntity oauthClientResourceRef) {
        oauthClientResourceRefService.save(oauthClientResourceRef);
        return R.ok(oauthClientResourceRef);
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public R<OauthClientResourceRefEntity> update(@Validated(UpdateGroup.class) @RequestBody OauthClientResourceRefEntity oauthClientResourceRef) {
        oauthClientResourceRefService.updateById(oauthClientResourceRef);
        return R.ok(oauthClientResourceRef);
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        oauthClientResourceRefService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
